import Vue from "vue";
import Vuex from "vuex";
import createPersistedState from "vuex-persistedstate";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    token: "",
    userinfo: {},
  },
  mutations: {
    setToken(state, token) {
      state.token = token;
    },
    setUserInfo(state, userinfo) {
      state.userinfo = userinfo;
    },
  },
  actions: {},
  modules: {},
  plugins: [
    createPersistedState({
      storage: window.sessionStorage,
      key: "my-Commerce",
      render(state) {
        // 要存储的数据:采用扩展运算符 的方式存储了state中的所有数据
        return { ...state };
      },
    }),
  ],
});
